package com.ray.project.oceanicwaveinformation;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.ray.project.oceanicbuoy.OceanicBuoy;
import com.ray.project.oceanicwaveinformation.R;

public class OceanicBuoyDetailActivity extends Activity {

   
	// This is the url for the NDBC RSS feed. A longitude, latitude and radius has to be added to the url
    public static final String NDBC_Buoy_Data_Url = "http://www.ndbc.noaa.gov/station_page.php?station=";

    public static OceanicBuoy buoyData = null;

    private Button buttonWeb;
    private TextView oceanicBuoyTitle;
    private TextView oceanicBuoyLocation;
    private TextView datePolled;
    private TextView oceanicBuoyAirTemperature;
    private TextView oceanicBuoyWaterTemperature;
    private TextView oceanicBuoyAtmosphericPressure;
    private TextView atmosphericTendency;
    private TextView buoyWindDirection;
    private TextView buoyWindSpeed;
    private TextView buoyWindGust;
    private TextView buoyWaveHeight;
    private TextView buoyWavePeriod;

    @Override
    public void onCreate(final Bundle icicle) {
        super.onCreate(icicle);
       
        this.setContentView(R.layout.oceanic_buoydetail_activity);

        this.buttonWeb = (Button) findViewById(R.id.button_web);
        this.oceanicBuoyTitle = (TextView) findViewById(R.id.bd_title);
        this.oceanicBuoyLocation = (TextView) findViewById(R.id.bd_location);
        this.datePolled = (TextView) findViewById(R.id.bd_date);
        this.oceanicBuoyAirTemperature = (TextView) findViewById(R.id.bd_air_temp);
        this.oceanicBuoyWaterTemperature = (TextView) findViewById(R.id.bd_water_temp);
        this.oceanicBuoyAtmosphericPressure = (TextView) findViewById(R.id.bd_atmo_press);
        this.atmosphericTendency = (TextView) findViewById(R.id.bd_atmo_tend);
        this.buoyWindDirection = (TextView) findViewById(R.id.bd_wind_dir);
        this.buoyWindSpeed = (TextView) findViewById(R.id.bd_wind_speed);
        this.buoyWindGust = (TextView) findViewById(R.id.bd_wind_gust);
        this.buoyWaveHeight = (TextView) findViewById(R.id.bd_wave_height);
        this.buoyWavePeriod = (TextView) findViewById(R.id.bd_wave_period);

        this.oceanicBuoyTitle.setText(OceanicBuoyDetailActivity.buoyData.getTitle());
        this.oceanicBuoyLocation.setText("Buoy Location:" + OceanicBuoyDetailActivity.buoyData.getLocation());
        this.datePolled.setText("Data Poll Date: "
            + (OceanicBuoyDetailActivity.buoyData.getDateString() != null ? OceanicBuoyDetailActivity.buoyData.getDateString() : "NA"));
        this.oceanicBuoyAirTemperature.setText("Air Temperature: "
            + (OceanicBuoyDetailActivity.buoyData.getAirTemperature() != null ? OceanicBuoyDetailActivity.buoyData.getAirTemperature() : "NA"));
        this.oceanicBuoyWaterTemperature.setText("Water Temperature: "
            + (OceanicBuoyDetailActivity.buoyData.getWaterTemperature() != null ? OceanicBuoyDetailActivity.buoyData.getWaterTemperature() : "NA"));
        this.oceanicBuoyAtmosphericPressure.setText("Barometric Pressure: "
            + (OceanicBuoyDetailActivity.buoyData.getAtmoPressure() != null ? OceanicBuoyDetailActivity.buoyData.getAtmoPressure() : "NA"));
        this.atmosphericTendency
            .setText("Barometric Trend: "
                + (OceanicBuoyDetailActivity.buoyData.getAtmoPressureTendency() != null ? OceanicBuoyDetailActivity.buoyData.getAtmoPressureTendency()
                    : "NA"));
        this.buoyWindDirection.setText("Wind Direction: "
            + (OceanicBuoyDetailActivity.buoyData.getWindDirection() != null ? OceanicBuoyDetailActivity.buoyData.getWindDirection() : "NA"));
        this.buoyWindSpeed.setText("Wind Speed: "
            + (OceanicBuoyDetailActivity.buoyData.getWindSpeed() != null ? OceanicBuoyDetailActivity.buoyData.getWindSpeed() : "NA"));
        this.buoyWindGust.setText("Wind Gust: "
            + (OceanicBuoyDetailActivity.buoyData.getWindGustSpeed() != null ? OceanicBuoyDetailActivity.buoyData.getWindGustSpeed() : "NA"));
        this.buoyWaveHeight.setText("Wave Height: "
            + (OceanicBuoyDetailActivity.buoyData.getWaveHeight() != null ? OceanicBuoyDetailActivity.buoyData.getWaveHeight() : "NA"));
        this.buoyWavePeriod.setText("Wave Period: "
            + (OceanicBuoyDetailActivity.buoyData.getWavePeriod() != null ? OceanicBuoyDetailActivity.buoyData.getWavePeriod() : "NA"));

        this.buttonWeb.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(OceanicBuoyDetailActivity.buoyData.getLink())));
            };
        });
    }

    @Override
    public void onStart() {
        super.onStart(); 
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
    }
}
